//
//  MeViewController.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/8.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit



class MeViewController: UITableViewController,MeHeaderDelegare {
    

    @IBOutlet weak var iconImg: UIImageView!
    
    let titleSource = ["交易明细","中奖纪录","收获地址","分享有礼"]
    

    override func viewDidLoad() {
        
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
         self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.edit, target: self, action: #selector(MeViewController.setting))
        self.title = "我的"

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension MeViewController {
    func setting() -> Void {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("设置按钮")))")
    }
}

// MARK: - Table view data source
extension MeViewController {
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return titleSource.count
    }
    
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 100
    }
    
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = Bundle.main.loadNibNamed("MeHeaderView", owner: nil, options: nil)?[0] as! MeHeaderView
        header.delegate = self
        return header
    }
    
}


// MARK: - Table view delegate
extension MeViewController {

    
    //创建各单元显示内容(创建参数indexPath指定的单元）
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil
        {
            cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
            cell?.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        }
        
        cell?.textLabel?.text = titleSource[indexPath.row]
        
        return cell!
        
    
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0: //交易明细

            self.navigationController?.pushViewController(BuyingDetailVC(), animated: true)
            
            print("\((#file as NSString).lastPathComponent):(\(#line)):(\("交易明细")))")
            break
        case 1: //中奖纪录
            self.navigationController?.pushViewController(RewardRecordVC(), animated: true)
            print("\((#file as NSString).lastPathComponent):(\(#line)):(\("中奖纪录")))")
            break
            
        case 2: //收货地址
//            self.navigationController?.pushViewController(AddressViewController(), animated: true)
//            self.navigationController?.pushViewController(AddressVC(), animated: true)
            self.navigationController?.pushViewController(PostViewController(), animated: true)
            
            print("\((#file as NSString).lastPathComponent):(\(#line)):(\("收货地址")))")
            
            
            break
            
        case 3: //分享有礼
            self.navigationController?.pushViewController(SharePaybackVC(), animated: true)
            print("\((#file as NSString).lastPathComponent):(\(#line)):(\("分享有礼")))")
            break
            
        default:
            break
        }
        
    }

}


// MARK:- 表头视图代理方法跳转(后期上传头像用)
extension MeViewController {
    func jumpToLogin() {
        
        print("-----")
        self.navigationController?.pushViewController(UserVC(), animated: true)
    }
}


